<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>find 命令之 xargs | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>find 命令之 xargs</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Linux命令/">Linux命令</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在使用 find命令的-exec选项处理匹配到的文件时， find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制，这样在find命令运行几分钟之后，就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在，特别是与find命令一起使用。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;find命令把匹配到的文件传递给xargs命令，而xargs命令每次只获取一部分文件而不是全部，不像-exec选项那样。这样它可以先处理最先获取的一部分文件，然后是下一批，并如此继续下去。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在有些系统中，使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程，并非将匹配到的文件全部作为参数一次执行；这样在有些情况下就会出现进程过多，系统性能下降的问题，因而效率不高； 而使用xargs命令则只有一个进程。另外，在使用xargs命令时，究竟是一次获取所有的参数，还是分批取得参数，以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。</p>
<h2 id="使用实例"><a href="#使用实例" class="headerlink" title="使用实例"></a>使用实例</h2><h3 id="实例1：查找系统中的每一个普通文件，然后使用-xargs-命令来测试他们分别属于哪类文件"><a href="#实例1：查找系统中的每一个普通文件，然后使用-xargs-命令来测试他们分别属于哪类文件" class="headerlink" title="实例1：查找系统中的每一个普通文件，然后使用 xargs 命令来测试他们分别属于哪类文件"></a>实例1：查找系统中的每一个普通文件，然后使用 xargs 命令来测试他们分别属于哪类文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -<span class="built_in">type</span> f -<span class="built_in">print</span> | xargs file</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 312</div><div class="line">-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2014.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 2 root root   4096 11-12 19:32 test3</div><div class="line">drwxrwxrwx 2 root root   4096 11-12 19:32 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># find . -type f -print | xargs file</span></div><div class="line">./log2014.log: empty</div><div class="line">./log2013.log: empty</div><div class="line">./log2012.log: ASCII text</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例2：在整个系统中查找内存信息转储文件（core-dump），然后把结果保存到-tmp-core-log-文件中"><a href="#实例2：在整个系统中查找内存信息转储文件（core-dump），然后把结果保存到-tmp-core-log-文件中" class="headerlink" title="实例2：在整个系统中查找内存信息转储文件（core dump），然后把结果保存到 /tmp/core.log 文件中"></a>实例2：在整个系统中查找内存信息转储文件（core dump），然后把结果保存到 /tmp/core.log 文件中</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find / -name <span class="string">"core"</span> -<span class="built_in">print</span> | xargs <span class="built_in">echo</span> <span class="string">""</span> &gt; /tmp/core.log</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># find / -name "core" -print | xargs echo "" &gt;/tmp/core.log</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd /tmp</span></div><div class="line">[root@localhost tmp]<span class="comment"># ll</span></div><div class="line">总计 16</div><div class="line">-rw-r--r-- 1 root root 1524 11-12 22:29 core.log</div><div class="line">drwx------ 2 root root 4096 11-12 22:24 ssh-TzcZDx1766</div><div class="line">drwx------ 2 root root 4096 11-12 22:28 ssh-ykiRPk1815</div><div class="line">drwx------ 2 root root 4096 11-03 07:11 vmware-root</div></pre></td></tr></table></figure>
<h3 id="实例3：在当前目录下查找所有用户具有读、写和执行权限的文件，并收回相应的写权限"><a href="#实例3：在当前目录下查找所有用户具有读、写和执行权限的文件，并收回相应的写权限" class="headerlink" title="实例3：在当前目录下查找所有用户具有读、写和执行权限的文件，并收回相应的写权限"></a>实例3：在当前目录下查找所有用户具有读、写和执行权限的文件，并收回相应的写权限</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -prem -7 -<span class="built_in">print</span> | xargs chmod 0-w</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 312</div><div class="line">-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2014.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxrwx 2 root root   4096 11-12 19:32 test3</div><div class="line">drwxrwxrwx 2 root root   4096 11-12 19:32 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># find . -perm -7 -print | xargs chmod o-w</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 312</div><div class="line">-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2014.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root   4096 11-12 19:32 test3</div><div class="line">drwxrwxr-x 2 root root   4096 11-12 19:32 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行命令后，文件夹 scf 、test3 和 test4 的权限都发生改变</p>
<h3 id="实例4：用-grep-命令在所有的普通文件中搜索-hostname-这个词"><a href="#实例4：用-grep-命令在所有的普通文件中搜索-hostname-这个词" class="headerlink" title="实例4：用 grep 命令在所有的普通文件中搜索 hostname 这个词"></a>实例4：用 grep 命令在所有的普通文件中搜索 hostname 这个词</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -<span class="built_in">type</span> f -<span class="built_in">print</span> | xargs grep <span class="string">"hostname"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># find . -type f -print | xargs grep "hostname"</span></div><div class="line">./log2013.log:hostnamebaidu=baidu.com</div><div class="line">./log2013.log:hostnamesina=sina.com</div><div class="line">./log2013.log:hostnames=<span class="literal">true</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例5：用-grep-命令在当前目录下的所有普通文件中搜索-hostnames-这个词"><a href="#实例5：用-grep-命令在当前目录下的所有普通文件中搜索-hostnames-这个词" class="headerlink" title="实例5：用 grep 命令在当前目录下的所有普通文件中搜索 hostnames 这个词"></a>实例5：用 grep 命令在当前目录下的所有普通文件中搜索 hostnames 这个词</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -name \* -<span class="built_in">type</span> f -<span class="built_in">print</span> | xargs grep <span class="string">"hostnames"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@peida <span class="built_in">test</span>]<span class="comment"># find . -name \* -type f -print | xargs grep "hostnames"</span></div><div class="line">./log2013.log:hostnamesina=sina.com</div><div class="line">./log2013.log:hostnames=<span class="literal">true</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;注意，在上例中， <code>\</code> 用来取消 find 命令中的 <code>*</code> 在 shell 中的特殊含义。</p>
<h3 id="实例6：使用-xargs-执行-mv"><a href="#实例6：使用-xargs-执行-mv" class="headerlink" title="实例6：使用 xargs 执行 mv"></a>实例6：使用 xargs 执行 mv</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -name <span class="string">"*.log"</span> | xargs -i mv &#123;&#125; test4</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 316</div><div class="line">-rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-12 22:44 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:25 log2014.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root   4096 11-12 22:54 test3</div><div class="line">drwxrwxr-x 2 root root   4096 11-12 19:32 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test4/</span></div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 0[root@localhost test4]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># find . -name "*.log" | xargs -i mv &#123;&#125; test4</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 12drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root 4096 11-13 05:50 test3</div><div class="line">drwxrwxr-x 2 root root 4096 11-13 05:50 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test4/</span></div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 304</div><div class="line">-rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-12 22:54 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:54 log2014.log</div><div class="line">[root@localhost test4]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例7：find-后执行-xargs-提示-xargs：argument-line-too-long-解决方法"><a href="#实例7：find-后执行-xargs-提示-xargs：argument-line-too-long-解决方法" class="headerlink" title="实例7：find 后执行 xargs 提示 xargs：argument line too long 解决方法"></a>实例7：find 后执行 xargs 提示 xargs：argument line too long 解决方法</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -<span class="built_in">type</span> f -atime +0 -print0 | xargs -0 -11 -t rm -f</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@pd test4]<span class="comment">#  find . -type f -atime +0 -print0 | xargs -0 -l1 -t rm -f</span></div><div class="line">rm -f </div><div class="line">[root@pdtest4]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;-11 是一次处理一个； -t 是处理之前打印出命令</p>
<h3 id="实例8：使用-i-参数默认的前面输出用-代替，-I-参数可以指定其他代替字符，如例子中的"><a href="#实例8：使用-i-参数默认的前面输出用-代替，-I-参数可以指定其他代替字符，如例子中的" class="headerlink" title="实例8：使用 -i 参数默认的前面输出用 {} 代替， -I 参数可以指定其他代替字符，如例子中的 []"></a>实例8：使用 -i 参数默认的前面输出用 {} 代替， -I 参数可以指定其他代替字符，如例子中的 []</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -name <span class="string">"file"</span> | xargs -I [] cp [] ..</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 12drwxr-xr-x 6 root root 4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root 4096 11-13 05:50 test3</div><div class="line">drwxrwxr-x 2 root root 4096 11-13 05:50 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test4</span></div><div class="line">[root@localhost test4]<span class="comment"># find . -name "file" | xargs -I [] cp [] ..</span></div><div class="line">[root@localhost test4]<span class="comment"># ll</span></div><div class="line">总计 304</div><div class="line">-rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-12 22:54 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-12 22:54 log2014.log</div><div class="line">[root@localhost test4]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 316</div><div class="line">-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root   4096 11-13 05:50 test3</div><div class="line">drwxrwxr-x 2 root root   4096 11-13 05:50 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用 -i 参数默认的前面输出用 {} 代替，-I 参数可以指定其他代替字符，如例子中的[]</p>
<h3 id="实例9：xargs-的-p-参数的使用"><a href="#实例9：xargs-的-p-参数的使用" class="headerlink" title="实例9：xargs 的 -p 参数的使用"></a>实例9：xargs 的 -p 参数的使用</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">find . -name <span class="string">"*.log"</span> | xargs -p -i mv &#123;&#125; ..</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 0</div><div class="line">-rw-r--r-- 1 root root 0 11-13 06:06 log2015.log</div><div class="line">[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 316</div><div class="line">-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root   4096 11-13 06:06 test3</div><div class="line">drwxrwxr-x 2 root root   4096 11-13 05:50 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test3</span></div><div class="line">[root@localhost test3]<span class="comment">#  find . -name "*.log" | xargs -p -i mv &#123;&#125; ..</span></div><div class="line">mv ./log2015.log .. ?...y</div><div class="line">[root@localhost test3]<span class="comment"># ll</span></div><div class="line">总计 0[root@localhost test3]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ll</span></div><div class="line">总计 316</div><div class="line">-rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log</div><div class="line">-rw-r--r-- 1 root root     61 11-13 06:03 log2013.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:03 log2014.log</div><div class="line">-rw-r--r-- 1 root root      0 11-13 06:06 log2015.log</div><div class="line">drwxr-xr-x 6 root root   4096 10-27 01:58 scf</div><div class="line">drwxrwxr-x 2 root root   4096 11-13 06:08 test3</div><div class="line">drwxrwxr-x 2 root root   4096 11-13 05:50 test4</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment">#</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;-p 参数会提示让你确认是否执行后面的命令，y 执行，n 不执行。</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/2. Linux 命令/21. find 命令之 xargs/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
